package code.bussiness;
import java.util.List;
import org.hibernate.*;

import code.hibernate.dao.CodetypeDAO;
import code.hibernate.po.*;
public class CodetypeBuss {
	CodetypeDAO kcdao= new CodetypeDAO();
	  public List findALL(){
		    List results=kcdao.findAll();
		    return results;
	  }
	  //保存
	  public void save(String ids, String codeTypes){
		  if(ids!=null&&(!ids.equals(""))){
			  String[] id=ids.split(",");
			  String[] codeType=codeTypes.split(",");
			  for(int i=0;i<id.length;i++){
				  try{
				      Codetype b=new Codetype(Integer.parseInt(id[i]),codeType[i]);
				      kcdao.save(b);
				  }
				  catch(HibernateException e){
					  e.printStackTrace();
				  }
			  }
		  }
		  else{//新建
			  try{
			      Codetype b=new Codetype(null,codeTypes);
			      kcdao.save(b);
			  }
			  catch(HibernateException e){
				  e.printStackTrace();
			  }
		  }
	  }
	//删除
	  public void delete(String ids){
		 if(ids!=null&&(!ids.equals(""))){
			 String[] id=ids.split(",");
			 for(int i=0;i<id.length;i++){
				 try{
				       Codetype po= kcdao.findById(Integer.parseInt(id[i]));
				       kcdao.delete(po);
				 }
				 catch(HibernateException e){
					  e.printStackTrace();
				  }
			 }
		 }
	  }
	  
}
